/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wasolicitudesfiec.Administracion.Materias.dataproviders;

import com.sun.data.provider.DataProviderException;
import com.sun.data.provider.FieldKey;
import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.AbstractTableDataProvider;
import com.sun.data.provider.impl.IndexRowKey;
import entidad.Materia;
import entidad.Rol;
import java.util.ArrayList;
import java.util.Vector;
/**
 *
 * @author kabad
 */
public class Dp_Materia extends AbstractTableDataProvider {
	private Vector<Materia> listaMaterias;
  //registro

    public Dp_Materia() {
        FieldKey key;
        key = new FieldKey("id");
        key.setDisplayName("id");
        addFieldKey(key);

        key = new FieldKey("nombre");
        key.setDisplayName("Nombre");
        addFieldKey(key);

        key = new FieldKey("codigo");
        key.setDisplayName("Código");
        addFieldKey(key);
    }

    @Override
    public Class getType(FieldKey fieldKey) throws DataProviderException {
        if (fieldKey.getFieldId().equals("id")) {
            return (new Integer(1)).getClass();
        } else {
            return (new String()).getClass();
        }
    }

    @Override
    public boolean isReadOnly(FieldKey fieldKey) throws DataProviderException {
        return true;
    }

    @Override
    public int getRowCount() throws DataProviderException {
		if (listaMaterias!=null)
			return listaMaterias.size();
		else
			return 0;
    }

    @Override
    public Object getValue(FieldKey fieldKey, RowKey row) throws DataProviderException {
        int indice = ((IndexRowKey) row).getIndex();
		if (fieldKey==null)
			return "";
		String fieldId = fieldKey.getFieldId();
		System.out.println("fieldId: "+fieldId);
        Materia registro = (Materia) listaMaterias.get(indice);
        if (fieldId.equals("nombre")) {
            return registro.getNombre() == null ? "No Disponible" : registro.getNombre();
        } else if (fieldId.equals("codigo")) {
            return registro.getCodigo() == null ? "No Disponible" : registro.getCodigo();
        } else if (fieldId.equals("id")) {
            return registro.getIdMateria() == 0 ? "No Disponible" : registro.getIdMateria();
        } else {
            return registro.getNombre();
        }
    }

	public void setListaRg_Materia(Vector<Materia> listaMaterias) {
		this.listaMaterias= listaMaterias;
	}

    @Override
    public void setValue(FieldKey fieldKey, RowKey row, Object value) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canInsertRow(RowKey beforeRow) throws DataProviderException {
        return false;
    }

    @Override
    public RowKey insertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canAppendRow() throws DataProviderException {
        return false;
    }

    @Override
    public RowKey appendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canRemoveRow(RowKey row) throws DataProviderException {
        return false;
    }

    @Override
    public void removeRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
